<?php

namespace App\Models;

use App\Http\Controllers\Admin\Traits\AdminTrait;
use App\Log\CompanyLog;
use Illuminate\Database\Eloquent\Model;

class Schools extends Model
{
    const OPERATE_PID = 1;
    const MODEL       = 'schools';

    use AdminTrait;

    protected $table      = 'schools';
    protected $guarded    = [];
    protected $dateFormat = 'U';

    public static function list($data = [], $skip = 0, $size = 10)
    {
        $select = self::where([]);
        if (!empty($data['name'])) {
            $select = $select->where('name', 'like', '%' . $data['name'] . '%');
        }

        if (!empty($data['domain_name'])) {
            $select = $select->where('domain_name', $data['domain_name']);
        }

        $count = $select->count();
        $list  = $select->skip($skip)->take($size)
            ->orderBy('created_at', 'desc')
            ->select(['*'])
            ->get()->toArray();

        return ['list' => $list, 'count' => $count];
    }

}
